home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / object / planet.pro < prev    next >
Text File  |  1997-07-08  |  7KB  |  203 lines

  1. ; $Id: planet.pro,v 1.4 1997/04/18 00:45:00 griz Exp $
  2. ;
  3. ; Copyright (c) 1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    PLANET
  8. ;
  9. ; PURPOSE:
  10. ;    This procedure demonstrates the use of object graphics to
  11. ;    manage local and global transformations. 
  12. ;
  13. ;    This procedure creates a simple widget application that allows 
  14. ;       the user to orbit a planet about a sun, or rotate the planet
  15. ;       about its own axis.
  16. ;
  17. ; CATEGORY:
  18. ;    Object graphics.
  19. ;
  20. ; CALLING SEQUENCE:
  21. ;    Planet
  22. ;
  23. ; MODIFICATION HISTORY:
  24. ;     Written by:    RF, September 1996.
  25. ;-
  26.  
  27. ;----------------------------------------------------------------------------
  28. ; PLANET_EVENT
  29. ;
  30. ; Purpose:
  31. ;  Handle events for the planet example.
  32. ;
  33. PRO planet_event, sEvent
  34.  
  35.     ; Handle a kill request.
  36.     IF TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST' THEN BEGIN
  37.         WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
  38.         OBJ_DESTROY, sState.oView
  39.         OBJ_DESTROY, sState.oWindow
  40.         WIDGET_CONTROL, sEvent.top, /DESTROY
  41.         RETURN
  42.     ENDIF
  43.  
  44.     ; Handle other events.
  45.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=uval
  46.     CASE uval OF
  47.         'MOVE': BEGIN  ; Turn on/off automotion.
  48.             WIDGET_CONTROl, sEvent.top, GET_UVALUE=sState
  49.             sState.automotion = sEvent.select
  50.             IF (sState.automotion EQ 1) THEN $
  51.                 WIDGET_CONTROL, sState.wBase, TIMER=sState.timer
  52.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState
  53.           END
  54.         'DRAW': BEGIN  ; Expose event.
  55.             IF (sEvent.type EQ 4) THEN BEGIN
  56.                 WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
  57.                 sState.oWindow->Draw, sState.oView 
  58.                 WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState
  59.             ENDIF
  60.           END
  61.         'PLANET': BEGIN ; Rotate the planet about its axis. 
  62.              WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
  63.              sState.oRot->Rotate, [0,0,1], -30 
  64.              sState.oWindow->Draw, sState.oView 
  65.              WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState
  66.           END
  67.         'TIMER' : BEGIN ; Timer event for automotion.
  68.              WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
  69.              IF (sState.automotion EQ 1) THEN BEGIN
  70.                  sState.oRot->Rotate, [0,0,1], -10 
  71.                  sState.oOrbit->Rotate, [0,1,0], -10
  72.                  sState.oCorr->Rotate, [0,1,0], 10
  73.              ENDIF 
  74.              IF (sState.automotion EQ 1) THEN BEGIN
  75.                  sState.oWindow->Draw, sState.oView 
  76.                  WIDGET_CONTROL, sEvent.id, TIMER=sState.timer
  77.              ENDIF
  78.              WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState
  79.           END 
  80.         'SUN': BEGIN    ; Orbit the planet about the sun.
  81.              WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
  82.          sState.oOrbit->Rotate, [0,1,0], -30
  83.          sState.oCorr->Rotate, [0,1,0], 30
  84.              sState.oWindow->Draw, sState.oView 
  85.              WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState
  86.           END 
  87.     ENDCASE
  88. END
  89.  
  90. ;----------------------------------------------------------------------------
  91. ; PLANET
  92. ;
  93. ; Purpose:
  94. ;  This procedure demonstrates the use of object graphics to manage local
  95. ;  and global transformations.  It creates a simple widget application 
  96. ;  that allows the user to orbit a planet about a sun, or rotate the planet
  97. ;  about its own axis.
  98. ;
  99. PRO Planet
  100.  
  101.     xdim = 480
  102.     ydim = 360
  103.  
  104.     ; Create the widgets.
  105.     wBase = WIDGET_BASE(/COLUMN, XPAD=0, YPAD=0, TITLE='Planet Example', $
  106.                         /TLB_KILL_REQUEST_EVENTS)
  107.     wDraw = WIDGET_DRAW(wBase, XSIZE=xdim, YSIZE=ydim, UVALUE='DRAW', $
  108.                         RETAIN=0, /EXPOSE_EVENTS, GRAPHICS_LEVEL=2)
  109.     wGuiBase = WIDGET_BASE(wBase, /ROW, UVALUE='TIMER' )
  110.     wButton = WIDGET_BUTTON(wGuiBase, VALUE="Spin Planet About Axis",$
  111.                             UVALUE='PLANET')
  112.     wButton = WIDGET_BUTTON(wGuiBase, VALUE="Orbit About Sun", UVALUE='SUN')
  113.     wBBase = WIDGET_BASE(wGuiBase, /NONEXCLUSIVE)
  114.     wButton = WIDGET_BUTTON(wBBase, VALUE="Automotion", UVALUE='MOVE')
  115.  
  116.     WIDGET_CONTROL, wBase, /REALIZE
  117.     WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
  118.  
  119.     ; Use low quality so the rotation of the planet about its axis can
  120.     ; be perceived.
  121.     oWindow->Setproperty, QUALITY=0
  122.  
  123.     ; Create a view.
  124.     aspect = FLOAT(xdim)/FLOAT(ydim)
  125.     myview = [-2.0,-2.0,4.0,4.0]
  126.     IF (aspect > 1) THEN BEGIN
  127.         myview[0] = myview[0] - ((aspect-1.0)*myview[2])/2.0 
  128.         myview[2] = myview[2] * aspect 
  129.     ENDIF ELSE BEGIN
  130.         myview[1] = myview[1] - (((1.0/aspect)-1.0)*myview[3])/2.0 
  131.         myview[3] = myview[3] * aspect 
  132.     ENDELSE
  133.     oView = OBJ_NEW('IDLgrView', COLOR=[60,60,60], PROJECTION=2, EYE=4, $
  134.                     ZCLIP=[2.0,-2.0], VIEWPLANE_RECT=myview )
  135.  
  136.     ; Create the top level model.
  137.     oTop = OBJ_NEW('IDLgrModel')
  138.  
  139.     ; Create some lights.
  140.     oLight1 = OBJ_NEW('IDLgrLight', LOCATION=[2,2,5], TYPE=2, INTENSITY=0.25)
  141.     oTop->Add, oLight1
  142.     oLight2 = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=0.5)
  143.     oTop->Add,oLight2
  144.  
  145.     ; Create the galaxy.
  146.     oGalaxy = OBJ_NEW('IDLgrModel')
  147.     oTop->Add, oGalaxy
  148.  
  149.     ; Create the sun.
  150.     oSun = OBJ_NEW('Orb', COLOR=[255,255,0], DENSITY=0.7)
  151.     oGalaxy->Add, oSun
  152.  
  153.     ; Create the rotational orbit.
  154.     oOrbit = obj_new('IDLgrModel')
  155.     oGalaxy->add,oOrbit
  156.  
  157.     ; Create the offset of the planet from the sun.
  158.     oOffset = OBJ_NEW('idlgrmodel')
  159.     oOffset->Translate,1.5,0,0
  160.     oOrbit->Add, oOffset
  161.  
  162.     ; Create the rotational correction of the planet as it orbits about 
  163.     ; the sun.
  164.     oCorr = OBJ_NEW('IDLgrModel')
  165.     oOffset->Add, oCorr
  166.  
  167.     ; Create the tilt of the planet's axis.
  168.     oTilt = OBJ_NEW('IDLgrModel')
  169.     oTilt->Rotate, [1,0,0], -60-180
  170.     oTilt->Rotate, [0,0,1], -30
  171.     oCorr->Add, oTilt
  172.  
  173.     ; Create the rotation of the planet about its axis.
  174.     oRot = OBJ_NEW('IDLgrModel')
  175.     oTilt->Add, oRot
  176.  
  177.     ; Create the axis of the planet.
  178.     oAxis = OBJ_NEW('IDLgrPolyline', [[0,0,-0.5],[0,0,0.5]], COLOR=[0,255,0])
  179.     oRot->Add, oAxis
  180.  
  181.     ; Create the planet. 
  182.     oPlanet = OBJ_NEW('Orb', COLOR=[0,0,255], RADIUS=0.25, DENSITY=0.3, $
  183.                       /TEX_COORDS)
  184.     oRot->Add, oPlanet
  185.  
  186.     ; Add the model tree to the view and draw.
  187.     oView->Add, oTop
  188.     oWindow->Draw, oView
  189.  
  190.     sState = {wBase: wGuiBase, $
  191.               timer: 0.4, $
  192.               automotion: 0, $
  193.               oRot:oRot, $
  194.               oOrbit:oOrbit, $
  195.               oCorr:oCorr, $
  196.               oWindow:oWindow, $
  197.               oView:oView $ 
  198.               } 
  199.     WIDGET_CONTROL, wBase, SET_UVALUE=sState
  200.  
  201.     XMANAGER, 'planet', wBase, /NO_BLOCK
  202. END
  203.